﻿@using Topro.Entity.Enum;
<div class="easyui-layout" data-options="fit: true">
    <div data-options="region: 'center', border: false" style="overflow: hidden;">
        <div class="easyui-layout" data-options="fit: true">
            <div data-options="region:'north',border: false,split:true" style="height:40px;">
                <div class="data-tools clearfix">
                    <div class="pull-left form-inline ">

                    </div>
                    <div class="pull-right">
                        <form class="form-inline" id="formSearch">
                            <div class="input-group input-group-sm">
                                <label class="input-group-addon m5_l">物料名称：</label>
                                <input class="form-control wd75" name="productName" type="text" autocomplete="off">
                            </div>
                            <div class="input-group input-group-sm">
                                <label class="input-group-addon m5_l">批号：</label>
                                <input class="form-control wd75" name="lotNo" type="text" autocomplete="off">
                            </div>
                            <div class="input-group input-group-sm">
                                <label class="input-group-addon m5_l">排：</label>
                                <input class="form-control wd50" name="pai" type="text" autocomplete="off">
                            </div>
                            <div class="input-group input-group-sm">
                                <label class="input-group-addon m5_l">列：</label>
                                <input class="form-control wd50" name="lie" type="text" autocomplete="off">
                            </div>
                            <div class="input-group input-group-sm">
                                <label class="input-group-addon m5_l">层：</label>
                                <input class="form-control wd50" name="ceng" type="text" autocomplete="off">
                            </div>
                            <button type="button" class="btn btn-default btn-sm active search"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                        </form>
                    </div>
                </div>
            </div>
            <div data-options="region:'center',split: false, border: false">
                <!-- 表格数据 -->
                <table id="commonInventoryDG"></table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    var commonInventoryDG = $('#commonInventoryDG');

    $(function () {
        //搜索
        $(".search").click(function(){
            //表单
            var searchform = $("#formSearch").serializeArray();
            //表单转为Json
            var queryParams = commonStockOut.getJson(searchform);

            commonInventoryDG.datagrid({
                queryParams: queryParams
            });

            return false;
        });
        //固定行
        Topro.UI.DataGrid(commonInventoryDG, {
            fit: true,
            method: "post",
            url: "@Url.Action("InventoryQuery", "Module")",
            queryParams: null,
            idField: 'id',
            pagination: true,
            singleSelect: true,
            rownumbers: true,
            showFooter: true,
            autoEditing:false,
            frozenColumns: [
                [
                    { field: 'ck', checkbox: true },
                    {
                        field: 'orderId',
                        title: '单据号',
                        width: 150,
                        align: 'left',
                        formatter: function (value, row, index) {
                            if (row.isContainer == @(IsContainer.空.GetHashCode())) {
                                return "{0}".format(row.orderId);
                            } else {
                                return "<a data-href=\"/Inventory/InventoryItem/{0}\" data-title=\"物料明细\" data-width=\"700\" data-height=\"400\" onclick=\"return Topro.UI.View(this)\">{1}</a>".format(row.id, row.orderId);
                            }
                        }
                    }
                ]
            ],
            columns: [
            [
                {
                    field: 'warehouseUnitTostring',
                    title: '库位 ',
                    width: 100,
                    align: 'left',
                    formatter: function (value, row, index) {

                        var result = "";

                        if (!Topro.Util.isNullOrEmptySpance(value)) {
                            result = value;
                        }

                        if (row.isContainer == @(IsContainer.空.GetHashCode())) {
                            result += "<span class='red bold'>(空)</span>"
                        }

                        return result;
                    }
                },
                {
                    field: 'productName',
                    title: '物料名称 ',
                    width: 250,
                    align: 'left'
                },
                {
                    field: 'lotNo1',
                    title: '批号1',
                    width: 100,
                    align: 'left'
                },
                {
                    field: 'lotNo2',
                    title: '批号2',
                    width: 100,
                    align: 'left'
                },
                {
                    field: 'stockQuantity',
                    title: '剩余库存',
                    width: 75,
                    align: 'right',
                    formatter: function (value, row, index) {
                        if (row.isContainer == @(IsContainer.空.GetHashCode())) {
                            return ""
                        } else {
                            return "<span class='red bold'>{0}</span>".format(value);
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    align: 'left',
                    width: 150
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center',
                    width: 140,
                    formatter: function (value, row, index) {

                        var result = value.replace("T", " ");

                        return result;
                    }
                }
            ]]
        });
    });

    function save() {
        //获取行
        debugger;

        var row = commonInventoryDG.datagrid('getSelected')

        if (Topro.Util.isNullOrEmptySpance(row)) {
            Topro.UI.Tip_danger("请选择.")
            return false;
        }

        Topro.UI.DialogOpener().set({
            inventoryId: row.id,
            orderId: row.orderId
        });

        Topro.UI.CloseDialog();
    }

    var commonStockOut = {
        getJson: function (array) {
            if (array != undefined && array.length > 0) {
                var json = {};
                $(array).each(function (i, v) {
                    json[v.name] = v.value;
                });
                return json;
            } else {
                return {};
            }
        }
    }
</script>
